<template>
  <!-- 放置一个图标 -->
  <div>
    <!-- 方式一:更换类名 -->
    <svg-icon
      :icon-class="screenOn ? 'exit-fullscreen' : 'fullscreen'"
      class="fullscreen"
      @click="handelToffle"
    />
    <!-- 方式二：v-if -->
    <!-- <svg-icon
      v-if="screenOn"
      icon-class="fullscreen"
      class="fullscreen"
      @click="toggleFullScreen"
    />
    <svg-icon
      v-else
      icon-class="fullscreen"
      class="fullscreen"
      @click="toggleFullScreen"
    /> -->
  </div>
</template>

<script>
export default {
  name: 'ScreenFull',
  data() {
    return {
      screenOn: false
    }
  },
  methods: {
    handelToffle() {
      if (this.screenOn) {
        document.exitFullscreen()
      } else {
        document.documentElement.requestFullscreen()
      }
      this.screenOn = !this.screenOn
    }
  }
}
</script>
<style  scoped>
.fullscreen {
  width: 40px;
  height: 40px;
  cursor: pointer;
}
</style>
